package pwd.allen.construct.composite.one;

import java.util.ArrayList;

/**
 * @author 门那粒沙
 * @create 2021-05-22 14:47
 **/
public class Composite implements IComponent {
    private ArrayList<IComponent> children = new ArrayList<IComponent>();
    @Override
    public void add(IComponent c) {
        children.add(c);
    }
    @Override
    public void remove(IComponent c) {
        children.remove(c);
    }
    @Override
    public IComponent getChild(int i) {
        return children.get(i);
    }
    @Override
    public void operation() {
        for (IComponent obj : children) {
            obj.operation();
        }
    }
}
